package com.example.myfoodrecipe.fragments.recipe.adapter

import android.util.Log
import android.view.View
import android.widget.ImageView
import androidx.databinding.BindingAdapter
import androidx.navigation.findNavController
import com.bumptech.glide.Glide
import com.example.myfoodrecipe.R
import com.example.myfoodrecipe.data.model.Result

object FoodBindingAdapter {
    @JvmStatic
    @BindingAdapter("loadImageWithUrl")
    fun loadImageWithUrl(imageView: ImageView,url: String){
        Glide.with(imageView.context)
            .load(url)
            .into(imageView)
    }

    @JvmStatic
    @BindingAdapter("loadIngredientImageWithName")
    fun loadIngredientImageWithName(imageView: ImageView,name: String){
        val baseUrl = "https://spoonacular.com/cdn/ingredients_250x250/"
        Glide.with(imageView.context)
            .load(baseUrl+name)
            .error(R.drawable.ic_launcher_background)
            .placeholder(R.drawable.ic_launcher_background)
            .into(imageView)
    }
    

    @JvmStatic
    @BindingAdapter("changeStatus")
    fun changeStatus(view: View,status: Boolean){
        view.isSelected = status
    }

    @JvmStatic
    @BindingAdapter("navigateToDetailFragment")
    fun navigateToDetailFragment(view: View,result: Result){
        view.findNavController().navigate(R.id.action_recipeFragment_to_detailFragment)
    }
}